import { createSlice } from '@reduxjs/toolkit'

// 创建store子模块
export const userSlice = createSlice({
  name: 'user',
//   初始值
  initialState: {
    name:'小明',
    age:22,
    sex:'男'
  },
  reducers: {
    // 修改
    changeName(state,action) {
        console.log(action)
        state.name = action.payload
    },
    changeAge(state,action) {
        state.age =state.age + action.payload
    }
  }
})

export const { changeName, changeAge } = userSlice.actions


export default userSlice.reducer